package com.sskj.one.view;

import android.app.Activity;
import android.webkit.JavascriptInterface;

import com.hjq.toast.ToastUtils;
import com.just.agentweb.AgentWeb;

import org.json.JSONObject;

import java.io.File;

public class AndroidInterfaceWeb {

    private AgentWeb agent;
    private Activity activity;
    private WebJsInterfaceCallback interfaceCallback;
    private String TAG = "AndroidInterfaceWeb";

    public AndroidInterfaceWeb(AgentWeb agent, Activity activity, WebJsInterfaceCallback interfaceCallback) {
        this.agent = agent;
        this.activity = activity;
        this.interfaceCallback = interfaceCallback;
    }

    @JavascriptInterface
    public void clickAddImage() {
        ToastUtils.show("hello");
//        Log.e(TAG,"method="+method+";params="+params+";callbackfunction="+callbackfunction);
//        ResultModel<UserModel> ret = new ResultModel<>();
//        if (!TextUtils.isEmpty(method)) {
//            switch (method) {
//                case "getUserinfo":
//                    UserModel userModel = new UserModel();
//                    AccountModel loginModel = UserInfoRepository.getInstance().getmAccountModel();
//                    if (loginModel != null) {
//                        userModel.setAppToken(loginModel.getUserAccessToken());
//                        ret.setCode(0);
//                        ret.setData(userModel);
//                    }else{
//                        ret.setCode(-1);
//                        ret.setMessage("app没有登录");
//                    }
//                    break;
//                case "doShare":
//                    ShareModel shareModel2 = GsonUtil.getGson().fromJson(params,ShareModel.class);
//                    if(interfaceCallback != null){
//                        interfaceCallback.doSahreInfo(shareModel2);
//                    }
//                    break;
//                case "openNewPage":
//                    try {
//                        JSONObject json = new JSONObject(params);
//                        String url = json.getString("url");
//                        String title = json.getString("title");
//                        Router.newIntent(activity).to(WebActivity.class)
//                                .putString(IntentKey.WEB_VIEW_URL,url)
//                                .putString(IntentKey.WEB_VIEW_TITLE,title)
//                                .launch();
//                    } catch (JSONException e) {
//                        e.printStackTrace();
//                    }
//                    break;
//                case "goLogin":
//                    if(interfaceCallback != null){
//                        interfaceCallback.goLogin(callbackfunction);
//                    }
//                    break;
//            }
//        }
//        RXThreadTask.run(AndroidSchedulers.mainThread(), new Consumer() {
//            @Override
//            public void accept(Object o) throws Exception {
//                if(agent != null){
//                    agent.getJsAccessEntrace().quickCallJs(callbackfunction, GsonUtil.getGson().toJson(ret));
//                }
//            }
//        });
    }

    public interface WebJsInterfaceCallback {
        void doSahreInfo(File shareModel);

        void goLogin(String jsCallback);
    }
}
